package components.location.map
{
	import com.esri.ags.Graphic;
	import com.esri.ags.SpatialReference;
	import com.esri.ags.geometry.Geometry;
	import com.esri.ags.geometry.MapPoint;
	import com.esri.ags.symbols.PictureMarkerSymbol;
	import com.esri.ags.symbols.Symbol;
	import com.esri.ags.utils.WebMercatorUtil;
	
	import components.valueobjects.GeoLocationVO;
	import components.valueobjects.LocationVO;
	
	public class CustomGraphic extends Graphic
	{
		public var dataObject:LocationVO;
		
		private var symbol1:PictureMarkerSymbol;
		private var symbol2:PictureMarkerSymbol;
		
		public function CustomGraphic(dataObject:LocationVO)
		{
			this.dataObject = dataObject;
			
			var mp1:MapPoint = new MapPoint(dataObject.geolocation.lon, dataObject.geolocation.lat, new SpatialReference(4326));
			var mp2:MapPoint = (WebMercatorUtil.geographicToWebMercator(mp1) as MapPoint);
			
			var iconWidth:int = 80; 
			var iconHeight:int = 80; 
			
			this.symbol1 = new PictureMarkerSymbol("images/location/map/"+dataObject.type+"_pin1.png",iconWidth,iconHeight,0,iconHeight/2,0);
			this.symbol2 = new PictureMarkerSymbol("images/location/map/"+dataObject.type+"_pin2.png",iconWidth,iconHeight,0,iconHeight/2,0);
			
			super((Geometry)(mp2), symbol1);
		}
		
		public function changeImage(clickedGraphic:CustomGraphic):void{
			if(this == clickedGraphic){
				this.symbol = symbol2;
			}else{
				this.symbol = symbol1;
			}
		}
	}
}